<?php
declare (strict_types = 1);

namespace app\middleware;

use think\facade\Session;
use think\response\Redirect;
use think\facade\Cookie;

class Check
{
    /**
     * 处理请求
     *
     * @param \think\Request $request
     * @param \Closure       $next
     * @return Response
     */
    public function handle($request, \Closure $next)
    {

        if(!Session::has('admin')){
            if(!Cookie::has('admin')){
                return redirect('login');
            }
            Session::set('admin',json_decode(Cookie::get('admin'),true));
        }
        return $next($request);
    }
}
